package com.lineage.server.clientpackets;

import com.lineage.echo.ClientExecutor;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.WorldNpc;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class C_BoardWrite extends ClientBasePacket {
  private static final Log _log = LogFactory.getLog(C_BoardWrite.class);
  
  public void start(byte[] decrypt, ClientExecutor client) {
    try {
      read(decrypt);
      L1PcInstance pc = client.getActiveChar();
      pc.isGhost();
      if (pc.isDead() || pc.isTeleport())
        return; 
      int objId = readD();
      L1NpcInstance npc = (L1NpcInstance)WorldNpc.get().map().get(Integer.valueOf(objId));
      if (npc == null)
        return; 
      String title = readS();
      if (title.length() > 16) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, "标题过长"));
        return;
      } 
      String content = readS();
      if (title.length() > 1000) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, "内容过长"));
        return;
      } 
      if (npc.ACTION != null) {
        pc.set_board_title(title);
        pc.set_board_content(content);
        npc.ACTION.action(pc, npc, "w", 0L);
      } 
    } catch (Exception exception) {
    
    } finally {
      over();
    } 
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
